// pages/metest/metest.js
import api from '../../api/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show:false,
    statusBarHeight: '',
    status: '',
    companyStatus:'',
    driver: '',
    bidlist: [],
    type: '',
    companyId: '',
    phone: '',
    companylist: [],
    list: [{
        status: 'waiting',
        name: '待发货',
        img: '../../image/tobesent.png'
      },
      {
        status: 'transit',
        name: '运输中',
        img: '../../image/intransit.png'
      },
      {
        status: 'arrived',
        name: '已收货',
        img: '../../image/received.png'
      },
      {
        status: 'delivered',
        name: '已签收',
        img: '../../image/beensigned.png'
      },
    ],
    personalList: [{
        status: 'delivered',
        name: '已签收',
        img: '../../image/mybeensigned.png'
      },
      {
        status: 'reviewed',
        name: '已评价',
        img: '../../image/myrated.png'
      }
    ],
    userlist: []
  },
  getSysInfo() {
    let that = this
    let res = wx.getSystemInfoSync();
    that.setData({
      statusBarHeight: res.statusBarHeight
    })
  },
  goToBeSent(e) {
    wx.navigateTo({
      url: `/pages/toBeSent/toBeSent?active=${e.currentTarget.dataset.type}`,
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          data: 'test'
        })
      }
    })
  },
  goToAllBidPrice(val) {
    wx.navigateTo({
      url: "/pages/allBidPriceOrder/allBidPriceOrder?val",
    })
  },
  changepassword(data) {
    wx.navigateTo({
      url: "/pages/upatepossword/upatepossword",
    })
  },
  goToAllPersonalOrder(data) {
    let that = this
    wx.navigateTo({
      url: `/pages/allPersonalOrder/allPersonalOrder?active=${data.currentTarget.dataset.type}`,
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          data: 'test'
        })
      }
    })
  },
  goToAllBidPriceOrder(data) {
    let that =this 
    if(data.currentTarget.dataset.type == 1){
      that.setData({
        companyStatus:1
      })
    }else if(data.currentTarget.dataset.type == 2){
      that.setData({
        companyStatus:2
      })
    }else{
      that.setData({
        companyStatus:0
      })
    }
    wx.navigateTo({
      url: `/pages/allBidPriceOrder/allBidPriceOrder?active=${that.data.companyStatus}`,
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          data: 'test'
        })
      }
    })
  },
  // logOut() {
  //   wx.clearStorageSync();
  //   wx.redirectTo({
  //     url: '/pages/index/index'
  //   })
  // },
  diglogback(){
    wx.clearStorageSync();
    wx.redirectTo({
      url: '/pages/login/login'
    })
  },
  logOut() {
    let that=this
    that.setData({
      show:true
    })
  },
  getbiglist() {
    // 改变this指向  
    let that = this;
    var companyId = wx.getStorageSync('companyid')
    let params = {
      companyId: companyId,
      companyStatus: 2
    }
    api.post('/companyInfoApp/findBidInfo', params).then(res => {
        that.setData({
          bidlist: res.data
        })
      })
      .catch(err => {
      })
  },
  getuserinfo() {
    let that = this;
    let id = wx.getStorageSync('id')
    // that.setData({
    //   id:id,
    // })
    api.post('/userInfoApp/getById', {
      id: id
    }).then(res => {
      that.setData({
        userlist: res.data,
        phone: res.data.phone
      })
    })
  },
  getcompanyinfo() {
    let that = this;
    let id = wx.getStorageSync('id')
    that.setData({
      id: id,
    })
    api.post('/companyInfoApp/getById', {
      id: that.data.id
    }).then(res => {
      that.setData({
        companylist: res.data
      })
    })
  },
  getTypeStorage() {
    let that = this
    let val = wx.getStorageSync('type')
    let index = wx.getStorageSync('isdriver')
    that.setData({
      type: val,
      driver: index
    })
    if (that.data.type == '1') {
      that.getbiglist()
      that.getcompanyinfo()
    } else {
      that.getuserinfo()
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    that.getSysInfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */

  onShow() {
    let that = this
    that.getTypeStorage()
    if (typeof that.getTabBar === 'function' && that.getTabBar()) {
      that.getTabBar().setData({
        // 根据tab的索引顺序是1
        select: 2
      })
    }
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})